#!/bin/bash

# 批量停止nohup启动的Spring Boot进程
for pid in $(ps -ef | grep java | grep abcshop-api | awk '{print $2}')
do
echo "Stopping process with pid $pid"
kill -15 $pid
done
echo "All Spring Boot processes have been stopped"

sleep 5
# 指定端口范围批量启动nohup形式的Spring Boot程序

array=("9000" "9001")
for i in "${array[@]}"
do
if [ -e /proc/${i}/fd/255 ]
then
 echo "Process with pid ${i} is running"
else
 echo "Process with pid ${i} is not running"
 nohup java -jar -Dloader.path=lib abcshop-api.jar --spring.profiles.active=pro --server.port=$i >/dev/null 2>&1 &
 sleep 1
fi
done
echo "All Spring Boot applications have been started"
